package com.yunchang.springboot.config.MWS;

import com.amazon.mws.finances._2015_05_01.MWSFinancesServiceAsyncClient;
import com.amazon.mws.finances._2015_05_01.MWSFinancesServiceClient;
import com.amazon.mws.finances._2015_05_01.MWSFinancesServiceConfig;

import java.util.concurrent.ExecutorService;

public class MWSFinancesDataServiceConfig {
    private static String ACCESS_KEY = "AKIAI7ISC53ENUSBNB2A";
    private static String SECRET_KEY = "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";
    private static final String APP_NAME = "AmazonJavascriptScratchpad";
    private static final String APP_VERSION = "1.0";
    private static final String SERVICE_URL = "https://mws.amazonservices.com";
    private static MWSFinancesServiceAsyncClient client = null;

    public MWSFinancesDataServiceConfig() {
    }

    public static MWSFinancesServiceClient getClient(String accessKey, String secretKey, String serviceURL) {
        return getAsyncClient(accessKey, secretKey, serviceURL);
    }

    public static synchronized MWSFinancesServiceAsyncClient getAsyncClient(String accessKey, String secretKey, String serviceURL) {
        if (client == null || !(ACCESS_KEY.equals(accessKey) && SECRET_KEY.equals(secretKey))) {
            com.amazon.mws.finances._2015_05_01.MWSFinancesServiceConfig config = new com.amazon.mws.finances._2015_05_01.MWSFinancesServiceConfig();
            config.setServiceURL(serviceURL);
            client = new MWSFinancesServiceAsyncClient(accessKey, secretKey, APP_NAME, APP_VERSION, config, (ExecutorService) null);
            ACCESS_KEY = accessKey;
            SECRET_KEY = secretKey;
        }

        return client;
    }
}